package com.example.boot032.controller;

import com.example.boot032.entity.Pet;
import com.example.boot032.mapper.PetMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class PetController {
    @Autowired
    PetMapper mapper;
    @RequestMapping("/select")
    public String select(){
        List<Pet> list = mapper.select();
        String html = "<table border='1'>";
        html+="<caption>员工列表</caption>";
        html +=" <tr><th>id</th> <th>种类</th> <th>数量</th><th>品种</th><th>操作</th></tr>";
        for (Pet p : list) {
            html +="<tr>";
            html +="<td>"+p.getId()+"</td>";
            html +="<td>"+p.getType()+"</td>";
            html +="<td>"+p.getNum()+"</td>";
            html +="<td>"+p.getBreed()+"</td>";
            html +="<td><a href='/delete?id="+p.getId()+"'>删除</a></td>";
            html +="</tr>";
        }
        html+="</table>";
        return html;
    }
    @RequestMapping("/insert")
    public String insert(Pet pet){
        mapper.insert(pet);
        return "添加万<a href='/'>首页</a>";
    }
    @RequestMapping("/delete")
    public String deleteById(int id){
        mapper.deleteById(id);
        return "删除成功<a href='/'>首页</a>";
    }
    @RequestMapping("/update")
    public String update(Pet pet){
        mapper.update(pet);
        return "修改陈<a href='/'>首页</a>";
    }
}
